package com.aiyige.page.authentication;

import android.content.Intent;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.page.authentication.model.Authentication;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = ARouterConfig.SelectAuthenticationMethodPage, extras = ARouterConfig.EXTRA_NEED_BINDPHONE)
public class SelectAuthenticationMethodPage extends AppCompatActivity {
    public static final int NEXT = 1;
    @BindView(R.id.titleBackBtn)
    ImageView titleBackBtn;
    @BindView(R.id.titleTv)
    TextView titleTv;
    @BindView(R.id.personalUserIv)
    ImageView personalUserIv;
    @BindView(R.id.textView7)
    TextView textView7;
    @BindView(R.id.personalUserLayout)
    ConstraintLayout personalUserLayout;
    @BindView(R.id.organizationUserIv)
    ImageView organizationUserIv;
    @BindView(R.id.textView8)
    TextView textView8;
    @BindView(R.id.organizationUserLayout)
    ConstraintLayout organizationUserLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_authentication_method_page);
        ButterKnife.bind(this);
        ARouter.getInstance().inject(this);
        titleTv.setText(R.string.user_authentication);
    }

    @OnClick({R.id.titleBackBtn, R.id.personalUserLayout, R.id.organizationUserLayout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.titleBackBtn:
                finish();
                break;
            case R.id.personalUserLayout:
                ARouter.getInstance()
                        .build(ARouterConfig.PersonalAuthenticationPage)
                        .withParcelable("authentication", Authentication.newBuilder()
                                .userType(Authentication.USER_TYPE_PERSONAL)
                                .readOnly(false)
                                .build())
                        .navigation(this, NEXT);
                break;
            case R.id.organizationUserLayout:
                ARouter.getInstance()
                        .build(ARouterConfig.OrganizationAuthenticationPage)
                        .withParcelable("authentication", Authentication.newBuilder()
                                .userType(Authentication.USER_TYPE_ORGANIZATION)
                                .readOnly(false)
                                .build())
                        .navigation(this, NEXT);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case NEXT:
                if (resultCode == RESULT_OK) {
                    finish();
                }
                break;
            default:
                super.onActivityResult(requestCode, resultCode, data);
                break;
        }
    }
}
